package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "管理端订单相关接口")
public class OrderController {

    @Autowired
    OrderService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("订单分页查询")
    public Result<PageResult> pageQuery(OrdersPageQueryDTO dto){
        PageResult result = orderService.adminPage(dto);
        return Result.success(result);
    }

    @GetMapping("/statistics")
    @ApiOperation("按状态数量统计")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO result = orderService.eachStatus();
        return Result.success(result);
    }

    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> getDetail(@PathVariable Long id){
        OrderVO result = orderService.getOrderWithDetail(id);
        return Result.success(result);
    }

    @ApiOperation("商家接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
        orderService.confirmWithCheckStatus(dto);
        return Result.success();
    }


    @PutMapping("/rejection")
    @ApiOperation("商家拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        orderService.rejection(dto);
        return Result.success();
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        orderService.adminCancel(dto);
        return Result.success();
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("商家派送订单")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("商家完成订单")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }
}
